export default {
	// tarbar的红点提示
	prompt(state) {
		// 对话页的通知
		let indexSum = state.notifySum + state.dialogueUnRead + ''
		if (indexSum > 0) {
			uni.setTabBarBadge({
				index: 0,
				text: indexSum
			})
		} else {
			uni.removeTabBarBadge({
				index: 0
			})
		}
		
		// 好友申请
		if (state.acquire > 0) {
			uni.setTabBarBadge({
				index: 1,
				text: state.acquire + ''
			});
		} else {
			uni.removeTabBarBadge({
				index: 1
			});
		}

		//发现页的通知(新访客，未读留言，新动态，新评论)
		if (state.newVisitor > 0 || state.messCount > 0 || state.dyNotify.length > 0 || state.count > 0) {
			uni.showTabBarRedDot({
				index: 2
			})
		} else {
			uni.hideTabBarRedDot({
				index: 2
			})
		}
	},
	// 修改聊天类型
	changeChatType(state, type) {
		state.chatType = type
	},
	// 修改聊天id
	changeChatId(state, id) {
		state.chatId = id
	},
	// 更新聊天信息（本地添加，减少请求）
	updateChatMsg(state, data) {
		let msg_list = state.chatHistory.msg_list
		if (msg_list.length > 0) {
			let lastItem = msg_list[msg_list.length - 1]
			let time = new Date(lastItem.date).getTime()
			let current = new Date(data.date).getTime()
			let distant = (current - time) / 1000 / 60
			distant >= 10 ? "" : data.date = ""
		}
		
		state.chatHistory.msg_list.push(data)
	},
	// 访问者的页码
	changeVisiPage(state, page) {
		state.visi_page = page
	},
	// 未读访问者信息
	changeVisitors(state, data) {
		state.visitors = data
	},
	// 修改评论通知（未读的条数）
	changeMessNotify(state, data) {
		let {
			user,
			date
		} = data
		let index = state.messNotify.findIndex(item => {
			return item.user == user && new Date(item.date).getTime() == new Date(date).getTime()
		})
		state.messNotify.splice(index, 1)
	},
	// 修改加载动画的标识
	changeIsLoading(state) {
		state.isLoading = !state.isLoading
	},
	// 修改聊天的用户名（群名）
	changeChatName(state, name) {
		state.name = name
	},
	// 聊天记录
	changeChatHistory(state, history) {
		state.chatHistory = history
	},
	
	// 群详情
	changeGroupInfo(state,obj){
		state.groupInfo = obj.group;
		this.commit("changeChatName",obj.group.name)
		state.g_nickName = obj.nickName;
	},
	// 动态通知表
	changeDyNotify(state, array) {
		state.dyNotify = array
		this.commit("prompt")
	},
	// 评论通知表
	changeComNotify(state, array) {
		state.comNotify = array
		state.comNotify.map(item => {
			if (!item.unRead) {
				state.count++
			}
		})
		this.commit("prompt")
	},

	// 好友请求的数量
	changeAcquire(state, number) {
		state.acquire = number;
		this.commit("prompt")
	},
	// 通知的数量
	changeNotifySum(state, number) {
		state.notifySum = number
		this.commit("prompt")
	},
	// 对话表里未读的信息数量
	changeDialogueUnRead(state, number) {
		state.dialogueUnRead = number
		this.commit("prompt")
	},
	// 新访客数量
	changeNewVisitorSum(state, number) {
		state.newVisitor = number
		this.commit("prompt")
	},
	// 未读留言
	changeMessageSum(state, number) {
		state.messCount = number
		this.commit("prompt")
	}
}
